<template>
  <section class="msg-list">
    <el-table :data="tableData" stripe height="calc(100vh - 215px)">
      <el-table-column prop="id" label="UserID" width="80">
      </el-table-column>
      <el-table-column label="可用" width="60">
        <template slot-scope="scope">
          <i v-if="scope.row.enable" class="el-icon-success"></i>
          <i v-else class="el-icon-error"></i>
        </template>
      </el-table-column>
      <el-table-column prop="user_name" label="用户名" width="100">
      </el-table-column>
      <el-table-column prop="phone" label="手机" width="120">
      </el-table-column>
      <el-table-column prop="email" label="邮箱" width="160">
      </el-table-column>
      <el-table-column label="创建日期" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span>{{scope.row.created_at|dateFormat('YYYY-MM-DD hh:mm:ss')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click.native.prevent="view(scope.row)"
                     type="text" size="small">
            正文<i class="el-icon-d-arrow-right"></i>
          </el-button>
          <el-button @click.native.prevent="toggle(scope.row)"
                     type="text" size="small">
            {{scope.row.enable?'禁用':'启用'}}<i class="el-icon-d-arrow-right"></i>
          </el-button>
          <el-button @click.native.prevent="del(scope.row)"
                     type="text" size="small">
            删除<i class="el-icon-d-arrow-right"></i>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :style="{marginTop:'10px'}"
      @size-change="sizeChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 40, 100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      background
      @current-change="listPage"
      :total="total">
    </el-pagination>
  </section>
</template>

<script>
import {UserService} from '@/service/api'

export default {
  data () {
    return {
      total: 0,
      tableData: [],
      pageSize: 10,
      currentPage: 1,
      dialogVisible: false
    }
  },
  mounted: function () {
    this.listPage(1)
  },
  methods: {
    sizeChange: function (val) {
      this.pageSize = val
      this.listPage(1, val)
    },
    listPage: function (val) {
      UserService.page(val, 5)
        .then(res => {
          if (res) {
            this.tableData = res.users
            this.total = res.total
          }
        })
    },
    view: function (item) {
    },
    del: function (item) {
    },
    toggle: function (item) {
    }
  }
}
</script>

<style scoped>
</style>
